<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>当家小管家 - 青岛版五年级数学</title>
    <style>
        body {
            font-family: "Microsoft YaHei", sans-serif;
            background: linear-gradient(135deg, #6ecbf5, #c2e9fb);
            margin: 0;
            padding: 20px;
            text-align: center;
            min-height: 100vh;
        }
        
        .container {
            max-width: 900px;
            margin: 0 auto;
            background: linear-gradient(135deg, #ffffff, #f0f9ff);
            border-radius: 20px;
            padding: 30px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.15);
            border: 5px solid #ffd700;
            position: relative;
            overflow: hidden;
        }
        
        .container::before {
            content: "";
            position: absolute;
            top: -50px;
            right: -50px;
            width: 150px;
            height: 150px;
            background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="50" cy="50" r="40" fill="%23FFD700" opacity="0.3"/></svg>') no-repeat;
            background-size: contain;
            transform: rotate(30deg);
        }
        
        .container::after {
            content: "";
            position: absolute;
            bottom: -30px;
            left: -30px;
            width: 100px;
            height: 100px;
            background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><polygon points="50,10 61,35 88,35 67,52 78,80 50,65 22,80 33,52 12,35 39,35" fill="%234a90e2" opacity="0.2"/></svg>') no-repeat;
            background-size: contain;
        }
        
        h1 {
            color: #ff6b6b;
            font-size: 32px;
            margin-bottom: 10px;
            text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
            position: relative;
            display: inline-block;
        }
        
        h1::after {
            content: "🏠";
            position: absolute;
            right: -40px;
            top: -10px;
            font-size: 36px;
        }
        
        .subtitle {
            color: #4a90e2;
            font-size: 18px;
            margin-bottom: 30px;
            font-weight: bold;
        }
        
        .difficulty-section {
            margin: 40px 0;
        }
        
        .section-title {
            color: #ff6b6b;
            font-size: 24px;
            margin-bottom: 20px;
            position: relative;
            display: inline-block;
        }
        
        .section-title::before {
            content: "📚";
            position: absolute;
            left: -40px;
            top: -5px;
            font-size: 28px;
        }
        
        .difficulty-buttons {
            display: flex;
            justify-content: center;
            gap: 25px;
            flex-wrap: wrap;
            margin-top: 30px;
        }
        
        .difficulty-btn {
            background: linear-gradient(135deg, #a1c4fd, #c2e9fb);
            border: none;
            border-radius: 15px;
            padding: 25px;
            width: 200px;
            cursor: pointer;
            transition: all 0.4s;
            font-size: 20px;
            font-weight: bold;
            color: #333;
            box-shadow: 0 6px 12px rgba(0,0,0,0.1);
            position: relative;
            overflow: hidden;
        }
        
        .difficulty-btn::before {
            content: "";
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
            transition: 0.5s;
        }
        
        .difficulty-btn:hover::before {
            left: 100%;
        }
        
        .difficulty-btn:hover {
            transform: translateY(-10px) scale(1.05);
            box-shadow: 0 12px 20px rgba(0,0,0,0.2);
        }
        
        .difficulty-btn.selected {
            background: linear-gradient(135deg, #ff9a9e, #fad0c4);
            color: white;
            transform: translateY(-5px);
            box-shadow: 0 8px 16px rgba(0,0,0,0.2);
        }
        
        .difficulty-desc {
            font-size: 15px;
            color: #666;
            margin-top: 15px;
            font-weight: 500;
        }
        
        .actions {
            margin-top: 40px;
            display: flex;
            justify-content: center;
            gap: 25px;
        }
        
        .action-btn {
            background: linear-gradient(135deg, #4a90e2, #6ecbf5);
            color: white;
            border: none;
            border-radius: 12px;
            padding: 15px 30px;
            font-size: 18px;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.3s;
            box-shadow: 0 4px 8px rgba(0,0,0,0.2);
            position: relative;
            overflow: hidden;
        }
        
        .action-btn::before {
            content: "";
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
            transition: 0.5s;
        }
        
        .action-btn:hover::before {
            left: 100%;
        }
        
        .action-btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 6px 12px rgba(0,0,0,0.3);
        }
        
        .action-btn:disabled {
            background: linear-gradient(135deg, #cccccc, #e0e0e0);
            cursor: not-allowed;
            transform: none;
            box-shadow: none;
        }
        
        .action-btn:disabled::before {
            display: none;
        }
        
        .game-rules {
            background: linear-gradient(135deg, #f9f9f9, #e3f2fd);
            border-left: 5px solid #ffd700;
            padding: 20px;
            text-align: left;
            margin-top: 30px;
            display: none;
            border-radius: 0 15px 15px 0;
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
        }
        
        .game-content {
            display: none;
            text-align: left;
        }
        
        .question-area {
            background: linear-gradient(135deg, #e0f7fa, #f8f8f8);
            border-radius: 15px;
            padding: 25px;
            margin: 25px 0;
            box-shadow: 0 4px 12px rgba(0,0,0,0.1);
            border: 2px dashed #4a90e2;
            position: relative;
        }
        
        .question-area::before {
            content: "📝";
            position: absolute;
            top: -15px;
            left: 20px;
            font-size: 30px;
            background: white;
            border-radius: 50%;
            width: 50px;
            height: 50px;
            display: flex;
            align-items: center;
            justify-content: center;
            box-shadow: 0 2px 6px rgba(0,0,0,0.2);
        }
        
        .input-area {
            margin: 25px 0;
            text-align: center;
        }
        
        .input-area label {
            font-size: 20px;
            color: #ff6b6b;
            font-weight: bold;
            display: block;
            margin-bottom: 15px;
        }
        
        .input-area input {
            padding: 15px;
            font-size: 22px;
            width: 200px;
            text-align: center;
            border: 3px solid #4a90e2;
            border-radius: 12px;
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
            transition: all 0.3s;
        }
        
        .input-area input:focus {
            border-color: #ff6b6b;
            box-shadow: 0 6px 12px rgba(0,0,0,0.2);
            outline: none;
            transform: scale(1.05);
        }
        
        .result-area {
            margin: 25px 0;
            padding: 20px;
            border-radius: 15px;
            display: none;
            text-align: center;
            font-size: 20px;
            font-weight: bold;
            box-shadow: 0 4px 12px rgba(0,0,0,0.1);
            position: relative;
            overflow: hidden;
        }
        
        .result-area::before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 5px;
        }
        
        .correct {
            background: linear-gradient(135deg, #d4edda, #c3e6cb);
            border: 2px solid #28a745;
            color: #155724;
        }
        
        .correct::before {
            background: #28a745;
        }
        
        .incorrect {
            background: linear-gradient(135deg, #f8d7da, #f5c6cb);
            border: 2px solid #dc3545;
            color: #721c24;
        }
        
        .incorrect::before {
            background: #dc3545;
        }
        
        #final-score {
            color: #ff6b6b;
            font-size: 36px;
        }
        
        .timer {
            position: absolute;
            top: 20px;
            right: 20px;
            background: linear-gradient(135deg, #ff6b6b, #ff8e8e);
            color: white;
            padding: 10px 15px;
            border-radius: 20px;
            font-weight: bold;
            box-shadow: 0 4px 8px rgba(0,0,0,0.2);
        }
        
        .timer::before {
            content: "⏰";
            margin-right: 5px;
        }
        
        .score-display {
            position: absolute;
            top: 20px;
            left: 20px;
            background: linear-gradient(135deg, #ffd700, #ffec8b);
            color: #333;
            padding: 10px 15px;
            border-radius: 20px;
            font-weight: bold;
            box-shadow: 0 4px 8px rgba(0,0,0,0.2);
        }
        
        .score-display::before {
            content: "💯";
            margin-right: 5px;
        }
        
        .wrong-question {
            background: #fff;
            border-radius: 10px;
            padding: 15px;
            margin: 15px 0;
            box-shadow: 0 2px 6px rgba(0,0,0,0.1);
            border-left: 4px solid #ff6b6b;
        }
        
        .wrong-question strong {
            color: #ff6b6b;
        }
        
        .wrong-question em {
            color: #666;
            font-size: 14px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="score-display">得分: <span id="current-score">0</span></div>
        <div class="timer">时间: <span id="time-left">10:00</span></div>
        <div id="stars-display" style="position: absolute; top: 20px; right: 200px; background: linear-gradient(135deg, #ffd700, #ffec8b); color: #333; padding: 10px 15px; border-radius: 20px; font-weight: bold; box-shadow: 0 4px 8px rgba(0,0,0,0.2);">
            ⭐ 星星: <span id="star-count">0</span>
        </div>
        
        <h1>青岛版五年级上册数学第一单元</h1>
        <h1>“当家小管家”购物模拟游戏</h1>
        <p class="subtitle">题目均源自【青岛版】五年级上册数学电子课本.pdf</p>
        
        <!-- 初始界面 -->
        <div id="start-screen">
            <div class="difficulty-section">
                <h2 class="section-title">请选择游戏模式</h2>
                <div class="difficulty-buttons">
                    <div>
                        <button class="difficulty-btn" onclick="selectMode('story')">
                            故事模式 📚
                        </button>
                        <p class="difficulty-desc">跟随小管家成长故事，逐步提升数学技能</p>
                    </div>
                    <div>
                        <button class="difficulty-btn" onclick="selectMode('practice')">
                            练习模式 🎯
                        </button>
                        <p class="difficulty-desc">直接选择难度进行专项练习</p>
                    </div>
                </div>
                
                <!-- 练习模式难度选择（默认隐藏） -->
                <div id="practice-difficulty" style="display: none; margin-top: 30px;">
                    <h3 class="section-title">请选择练习难度</h3>
                    <div class="difficulty-buttons">
                        <div>
                            <button class="difficulty-btn" onclick="selectDifficulty('simple')">
                                简单难度 🌟
                            </button>
                            <p class="difficulty-desc">小数乘整数、简单小数乘小数</p>
                        </div>
                        <div>
                            <button class="difficulty-btn" onclick="selectDifficulty('advanced')">
                                进阶难度 🚀
                            </button>
                            <p class="difficulty-desc">连乘、乘加混合运算</p>
                        </div>
                        <div>
                            <button class="difficulty-btn" onclick="selectDifficulty('olympiad')">
                                奥赛难度 🏆
                            </button>
                            <p class="difficulty-desc">运算律巧算、促销场景优化计算</p>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="actions">
                <button class="action-btn" onclick="showRules()">游戏规则 📖</button>
                <button class="action-btn" id="start-btn" onclick="startGame()" disabled>开始游戏 🎮</button>
            </div>
            
            <div id="rules-modal" class="game-rules">
                <h3>游戏副本规则</h3>
                <p>1. 故事模式：跟随小管家的成长故事，通过解决数学问题推进剧情</p>
                <p>2. 练习模式：直接选择难度进行专项数学练习</p>
                <p>3. 根据题目要求计算商品总价或解决数学问题</p>
                <p>4. 输入答案并提交，系统会自动判断对错</p>
                <p>5. 正确答题可获得分数和星星奖励，错误可重新尝试</p>
                <p>6. 游戏时长为10分钟，结束后可查看得分和错题</p>
                <p>7. 简单难度每题20分，进阶难度每题30分，奥赛难度每题50分</p>
            </div>
        </div>
        
        <!-- 游戏界面 -->
        <div id="game-screen" class="game-content">
            <h2 id="game-title">简单难度 - 购物计算</h2>
            <div class="question-area">
                <h3 id="question-text">你是当家小管家，需购买25千克大米，大米单价4.72元/千克，请计算总费用</h3>
                <p id="question-source">题目源自：电子课本第一单元自主练习</p>
            </div>
            
            <div class="input-area">
                <label for="answer-input">请输入总价（元）：</label><br>
                <input type="number" id="answer-input" step="0.01" placeholder="0.00">
                <button class="action-btn" onclick="submitAnswer()" style="margin-left: 10px;">提交答案</button>
            </div>
            
            <div id="result-area" class="result-area">
                <p id="result-text"></p>
            </div>
            
            <div class="actions">
                <button class="action-btn" onclick="nextQuestion()">继续答题</button>
                <button class="action-btn" onclick="endGame()">结束游戏</button>
            </div>
        </div>
        
        <!-- 结果界面 -->
        <div id="result-screen" class="game-content">
            <h2>游戏结束！</h2>
            <h3>你的总得分：<span id="final-score">0</span>分</h3>
            <h3>收集星星：<span id="final-stars">0</span>颗 ⭐</h3>
            
            <div id="achievements-section" style="margin: 20px 0; text-align: left; background: linear-gradient(135deg, #ffd700, #ffec8b); padding: 15px; border-radius: 10px;">
                <div id="achievements-list"></div>
            </div>
            
            <div id="wrong-questions" style="margin: 20px 0; text-align: left;">
                <h3>错题回顾：</h3>
                <div id="wrong-list"></div>
            </div>
            
            <div class="actions">
                <button class="action-btn" onclick="resetGame()">重新选择难度</button>
            </div>
        </div>
    </div>

    <script src="simpleQuestions.js"></script>
    <script src="simpleQuestionsPart2.js"></script>
    <script src="advancedQuestions.js"></script>
    <script src="advancedQuestionsPart2.js"></script>
    <script src="olympiadQuestions_part1.js"></script>
    <script src="olympiadQuestions_part2.js"></script>
    <script src="olympiadQuestions_part3.js"></script>
    <script src="olympiadQuestions_part4.js"></script>
    <script>
        // 合并题库
        const questionBank = {
            simple: [...simpleQuestions, ...simpleQuestionsPart2],
            advanced: [...advancedQuestions, ...advancedQuestionsPart2],
            olympiad: [...olympiadQuestions_part1, ...olympiadQuestions_part2, ...olympiadQuestions_part3, ...olympiadQuestions_part4]
        };
        
        // 全局变量
        let selectedDifficulty = '';
        let currentQuestion = null;
        let score = 0;
        let stars = 0; // 星星奖励计数器
        let wrongQuestions = [];
        let gameTimer = null;
        let timeLeft = 600; // 10分钟 = 600秒
        let usedQuestions = { simple: [], advanced: [], olympiad: [] }; // 记录已使用的题目
        
        // 故事模式变量
        let currentStoryChapter = 1;
        let storyDifficulty = 'simple';
        let storyProgress = 0; // 故事进度计数器
        
        // 模式选择函数
        function selectMode(mode) {
            // 重置所有按钮状态
            document.querySelectorAll('.difficulty-btn').forEach(btn => {
                btn.classList.remove('selected');
            });
            
            // 设置选中状态
            event.target.classList.add('selected');
            
            if (mode === 'story') {
                // 故事模式下隐藏难度选择，直接开始
                document.getElementById('practice-difficulty').style.display = 'none';
                selectedDifficulty = 'story';
                document.getElementById('start-btn').disabled = false;
            } else if (mode === 'practice') {
                // 练习模式下显示难度选择
                document.getElementById('practice-difficulty').style.display = 'block';
                selectedDifficulty = '';
                document.getElementById('start-btn').disabled = true;
            }
        }
        
        // 难度选择函数（用于练习模式）
        function selectDifficulty(difficulty) {
            // 重置所有按钮状态
            document.querySelectorAll('.difficulty-btn').forEach(btn => {
                btn.classList.remove('selected');
            });
            
            // 设置选中状态
            event.target.classList.add('selected');
            selectedDifficulty = difficulty;
            
            // 启用开始游戏按钮
            document.getElementById('start-btn').disabled = false;
        }
        
        // 显示游戏规则
        function showRules() {
            const rulesModal = document.getElementById('rules-modal');
            rulesModal.style.display = rulesModal.style.display === 'block' ? 'none' : 'block';
        }
        
        // 开始游戏
        function startGame() {
            if (!selectedDifficulty) {
                alert('请先选择游戏模式和难度！');
                return;
            }
            
            // 隐藏初始界面，显示游戏界面
            document.getElementById('start-screen').style.display = 'none';
            document.getElementById('game-screen').style.display = 'block';
            
            // 设置游戏标题
            const titles = {
                'simple': '简单难度 - 购物计算',
                'advanced': '进阶难度 - 复杂计算',
                'olympiad': '奥赛难度 - 巧算挑战',
                'story': '故事模式 - 小管家成长之旅'
            };
            document.getElementById('game-title').textContent = titles[selectedDifficulty];
            
            // 初始化游戏
            score = 0;
            wrongQuestions = [];
            timeLeft = 600; // 重置时间
            
            // 如果是故事模式，设置初始难度为简单
            if (selectedDifficulty === 'story') {
                currentStoryChapter = 1;
                storyDifficulty = 'simple';
            } else {
                storyDifficulty = selectedDifficulty;
            }
            
            // 开始计时
            startTimer();
            
            // 加载第一题
            loadQuestion();
        }
        
        // 开始计时器
        function startTimer() {
            gameTimer = setInterval(() => {
                timeLeft--;
                if (timeLeft <= 0) {
                    endGame();
                }
            }, 1000);
        }
        
        // 获取未使用的题目索引
        function getUnusedQuestionIndex(bank, usedList) {
            // 如果已使用的题目超过80%，重置已使用列表以确保题目多样性
            if (usedList.length > bank.length * 0.8) {
                usedQuestions[selectedDifficulty] = [];
            }
            
            const availableIndices = [];
            for (let i = 0; i < bank.length; i++) {
                if (!usedList.includes(i)) {
                    availableIndices.push(i);
                }
            }
            
            // 如果所有题目都已使用，重置已使用列表
            if (availableIndices.length === 0) {
                usedQuestions[selectedDifficulty] = [];
                for (let i = 0; i < bank.length; i++) {
                    availableIndices.push(i);
                }
            }
            
            // 从可用索引中随机选择一个
            const randomIndex = Math.floor(Math.random() * availableIndices.length);
            return availableIndices[randomIndex];
        }
        
        // 加载题目
        function loadQuestion() {
            // 确定使用的难度级别
            const difficultyLevel = selectedDifficulty === 'story' ? storyDifficulty : selectedDifficulty;
            
            // 从对应难度题库中随机选择未使用过的题目
            const bank = questionBank[difficultyLevel];
            const index = getUnusedQuestionIndex(bank, usedQuestions[difficultyLevel]);
            
            // 记录已使用的题目
            usedQuestions[difficultyLevel].push(index);
            currentQuestion = bank[index];
            
            // 显示题目
            if (selectedDifficulty === 'story') {
                // 故事模式添加章节背景
                const chapterTitles = {
                    1: "第1章：初出茅庐的小管家",
                    2: "第2章：熟练的购物助手",
                    3: "第3章：智慧理财小专家"
                };
                
                const chapterDescriptions = {
                    1: "帮助家里购买日常用品",
                    2: "陪同家人去超市大采购",
                    3: "为家庭制定理财计划"
                };
                
                document.getElementById('question-text').textContent = `${chapterTitles[currentStoryChapter]} - ${chapterDescriptions[currentStoryChapter]}：你是当家小管家，需${currentQuestion.text}`;
            } else {
                document.getElementById('question-text').textContent = "你是当家小管家，需" + currentQuestion.text;
            }
            
            document.getElementById('question-source').textContent = "题目源自：" + currentQuestion.source;
            
            // 清空输入框和结果区域
            document.getElementById('answer-input').value = '';
            document.getElementById('result-area').style.display = 'none';
        }
        
        // 提交答案
        function submitAnswer() {
            const userAnswer = parseFloat(document.getElementById('answer-input').value);
            
            if (isNaN(userAnswer)) {
                alert('请输入有效的数字！');
                return;
            }
            
            const resultArea = document.getElementById('result-area');
            const resultText = document.getElementById('result-text');
            
            // 判断答案是否正确（允许小数点后两位的误差）
            if (Math.abs(userAnswer - currentQuestion.answer) < 0.01) {
                // 正确
                resultArea.className = 'result-area correct';
                
                // 根据难度给予不同分数和星星
                let points = 0;
                let starReward = 0;
                const difficultyLevel = selectedDifficulty === 'story' ? storyDifficulty : selectedDifficulty;
                
                if (difficultyLevel === 'simple') {
                    points = 20;
                    starReward = 1;
                    score += 20;
                } else if (difficultyLevel === 'advanced') {
                    points = 30;
                    starReward = 2;
                    score += 30;
                } else if (difficultyLevel === 'olympiad') {
                    points = 50;
                    starReward = 3;
                    score += 50;
                }
                
                // 添加星星奖励
                stars += starReward;
                document.getElementById('star-count').textContent = stars;
                document.getElementById('current-score').textContent = score;
                
                // 故事模式特殊反馈
                if (selectedDifficulty === 'story') {
                    resultText.textContent = `计算正确！你是合格的小管家～ 获得${points}分和${starReward}颗星星⭐`;
                } else {
                    resultText.textContent = `计算正确！你是合格的小管家～ 获得${points}分和${starReward}颗星星⭐`;
                }
            } else {
                // 错误
                resultArea.className = 'result-area incorrect';
                resultText.textContent = `计算有误，再试试吧！正确答案是：${currentQuestion.answer}元`;
                
                // 记录错题
                wrongQuestions.push({
                    question: currentQuestion.text,
                    correctAnswer: currentQuestion.answer,
                    userAnswer: userAnswer,
                    source: currentQuestion.source
                });
            }
            
            resultArea.style.display = 'block';
        }
        
        // 下一题
        function nextQuestion() {
            if (selectedDifficulty === 'story') {
                // 故事模式下更新进度和章节
                storyProgress++;
                
                // 每5题提升一个章节和难度
                if (storyProgress % 5 === 0) {
                    if (currentStoryChapter < 3) {
                        currentStoryChapter++;
                        
                        // 根据章节调整难度
                        if (currentStoryChapter === 2) {
                            storyDifficulty = 'advanced';
                        } else if (currentStoryChapter === 3) {
                            storyDifficulty = 'olympiad';
                        }
                        
                        // 显示章节提升提示
                        alert(`恭喜你完成了第${currentStoryChapter - 1}章！现在进入第${currentStoryChapter}章，挑战更难的题目吧！`);
                    }
                }
            }
            
            loadQuestion();
        }
        
        // 结束游戏
        function endGame() {
            // 清除计时器
            clearInterval(gameTimer);
            
            // 隐藏游戏界面，显示结果界面
            document.getElementById('game-screen').style.display = 'none';
            document.getElementById('result-screen').style.display = 'block';
            
            // 显示最终得分和星星
            document.getElementById('final-score').textContent = score;
            document.getElementById('final-stars').textContent = stars;
            
            // 显示成就
            const achievementsList = document.getElementById('achievements-list');
            let achievementsHTML = '<h3>🏆 本次游戏成就 🏆</h3><ul>';
            
            // 根据得分给予成就
            if (score >= 500) {
                achievementsHTML += '<li>🥇 数学小天才：得分超过500分</li>';
            } else if (score >= 300) {
                achievementsHTML += '<li>🥈 计算小能手：得分超过300分</li>';
            } else if (score >= 100) {
                achievementsHTML += '<li>🥉 进步小达人：得分超过100分</li>';
            }
            
            // 根据星星数量给予成就
            if (stars >= 20) {
                achievementsHTML += '<li>⭐ 星星收集家：收集超过20颗星星</li>';
            } else if (stars >= 10) {
                achievementsHTML += '<li>⭐ 星星爱好者：收集超过10颗星星</li>';
            }
            
            // 根据正确率给予成就
            const totalQuestions = storyProgress > 0 ? storyProgress : (wrongQuestions.length + Math.max(1, 10 - wrongQuestions.length));
            const correctRate = totalQuestions > 0 ? ((totalQuestions - wrongQuestions.length) / totalQuestions * 100) : 0;
            
            if (correctRate >= 90) {
                achievementsHTML += '<li>🎯 准确率大师：正确率超过90%</li>';
            } else if (correctRate >= 80) {
                achievementsHTML += '<li>🎯 准确率高手：正确率超过80%</li>';
            }
            
            achievementsHTML += '</ul>';
            achievementsList.innerHTML = achievementsHTML;
            
            // 显示错题
            const wrongList = document.getElementById('wrong-list');
            if (wrongQuestions.length === 0) {
                wrongList.innerHTML = '<p>恭喜！本次答题全对！</p>';
            } else {
                let wrongHTML = '<ul>';
                wrongQuestions.forEach((item, index) => {
                    wrongHTML += `<li>
                        <p><strong>题目${index + 1}：</strong>${item.question}</p>
                        <p><strong>你的答案：</strong>${item.userAnswer}元 <strong>正确答案：</strong>${item.correctAnswer}元</p>
                        <p><em>题目来源：${item.source}</em></p>
                        <p><em>参考电子课本的计算方法：可参考小数乘法竖式计算方法</em></p>
                        <br>
                    </li>`;
                });
                wrongHTML += '</ul>';
                wrongList.innerHTML = wrongHTML;
            }
        }
        
        // 重新开始游戏
        function resetGame() {
            // 清除计时器
            clearInterval(gameTimer);
            
            // 重置状态
            selectedDifficulty = '';
            currentQuestion = null;
            score = 0;
            stars = 0;
            wrongQuestions = [];
            timeLeft = 600;
            usedQuestions = { simple: [], advanced: [], olympiad: [] }; // 重置已使用题目列表
            
            // 重置故事模式变量
            currentStoryChapter = 1;
            storyDifficulty = 'simple';
            storyProgress = 0;
            
            // 更新显示
            document.getElementById('star-count').textContent = stars;
            document.getElementById('current-score').textContent = score;
            
            // 重置按钮状态
            document.querySelectorAll('.difficulty-btn').forEach(btn => {
                btn.classList.remove('selected');
            });
            document.getElementById('start-btn').disabled = true;
            
            // 隐藏所有界面，显示初始界面
            document.getElementById('result-screen').style.display = 'none';
            document.getElementById('game-screen').style.display = 'none';
            document.getElementById('start-screen').style.display = 'block';
            
            // 隐藏规则
            document.getElementById('rules-modal').style.display = 'none';
        }
    </script>
</body>
</html>